using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using DTO;

namespace DAO
{
    public class ThiSinh_DAO
    {
        public DataTable TraCuuThongTinDuThi(int MaTS, ref float DTB)
        {
            try
            {
                SqlConnection cn = new SqlConnection();
                DataProvider dp = new DataProvider();
                cn = dp.ConnectionData();
                cn.Open();

                SqlCommand cmd = cn.CreateCommand();
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.CommandText = "sp_TraCuuTTTS";

                SqlParameter para = new SqlParameter("@MaTS", MaTS);
                cmd.Parameters.Add(para);

                para = new SqlParameter("@DTB", DTB);
                para.Direction = ParameterDirection.Output;
                cmd.Parameters.Add(para);

                DataTable dt = new DataTable();
                SqlDataAdapter da = new SqlDataAdapter(cmd);
                da.Fill(dt);

                String str = cmd.Parameters["@DTB"].Value.ToString();
                DTB = float.Parse(str);

                cn.Close();
                return dt;
            }
            catch (SqlException e)
            {
                throw e;
            }
        }

        public void CapNhatDiemTS(int MaTS, float Diem, float DiemNoi, float DiemViet, float DiemNghe)
        {
            try
            {
                SqlConnection cn = new SqlConnection();
                DataProvider dp = new DataProvider();
                cn = dp.ConnectionData();
                cn.Open();

                SqlCommand cmd = cn.CreateCommand();
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.CommandText = "sp_CapNhatDiem";

                SqlParameter para = new SqlParameter ("@MaTS", MaTS);
                cmd.Parameters.Add(para);

                para = new SqlParameter("@Diem", Diem);
                cmd.Parameters.Add(para);

                para = new SqlParameter("@DiemNghe", DiemNghe);
                cmd.Parameters.Add(para);

                para = new SqlParameter("@DiemNoi", DiemNoi);
                cmd.Parameters.Add(para);

                para = new SqlParameter("@DiemViet", DiemViet);
                cmd.Parameters.Add(para);

                cmd.ExecuteNonQuery();
                cn.Close();

            }
            catch (SqlException e)
            {
                throw e;
            }
        }
    }
}
